package action;

import javax.servlet.ServletContext;

import org.apache.struts2.util.ServletContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import bean.ICalculator;

public class Action implements ServletContextAware{
	private ServletContext servletContext;
	private int a;
	private int b;
	private int sum;
	
	public String execute(){
		WebApplicationContext ac = 
			WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
		ICalculator cal = (ICalculator)ac.getBean("calculator");
		sum = cal.sum(10, 20);
		return "success";
	}
	
	public int getA() {
		return a;
	}
	public void setA(int a) {
		this.a = a;
	}
	public int getB() {
		return b;
	}
	public void setB(int b) {
		this.b = b;
	}

	@Override
	public void setServletContext(ServletContext servletContext) {
		this.servletContext=servletContext;
	}

	public int getSum() {
		return sum;
	}

	public void setSum(int sum) {
		this.sum = sum;
	}
	

}
